# TODO 导入pymysql
import pymysql
# TODO 创建连接对象
conn = pymysql.connect(host='localhost', user='root', password='root', database='advanced', port=3306, charset='utf8')
# TODO 获取游标对象
cursor = conn.cursor()
# TODO 执行sql语句
# TODO 提交或者回滚
try:
    sql = "insert into student(stu_id, stu_no, stu_name) values (8, 'itsrc-15', '王牌')"
    sul = cursor.execute(sql)                 # 返回受影响行数
    print('受影响行数%d' % sul)
except Exception as e:                        # 注意: 提交或者返回使用的是数据的连接对象
    print(e)                                  # 有异常,回滚
    conn.rollback()
else:
    conn.commit()                             # 没有异常,提交
# TODO 关闭连接对象
conn.close()
# TODO 关闭游标对象
cursor.close()


